<?php
	/**
	* Video Module Datatype
	* @author trungdt
	* @since Sep 27, 2011
	* 
	*/
	class videomodule_video {
		/**
		* Video Form
		* 
		* @param mixed $object
		* @return form
		*/
		function video_form($object, $loc) {
			if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
			exponent_forms_initialize();
			
			global $db;
			
			$cats=$db->selectDropdown("videomodule_cat","title", " location_data = '".serialize($loc)."' ");
			
			$form = new form();
			if (!isset($object->id)) {
				$object->title = '';
				$object->title2 = '';
				$object->seo_name = '';
				$object->search_des = '';
				$object->video_type = 0;
				$object->file_id= 0;
				$object->thumbnail= 0;
				$object->youtube_embed= "";
				$object->use_own_thumbnail= 0;
				foreach ($cats as $key=>$value) {
					$object->cat_id=$key;
					break;
				}
				$object->prior= 0;
				$object->highlighted= 0;
			} else {
				$form->meta('id',$object->id);
			}

			$form->register('title','Video Title',new textcontrol($object->title));
			$form->register('title2','Second video title',new textcontrol($object->title2));
			$form->register('seo_name','Seo Name',new textcontrol($object->seo_name));
			$form->register("",null,new htmlcontrol("<p>Leave SEO field blank for automatic generate SEO name</p>"));
			$form->register('search_des','Search Description',new texteditorcontrol($object->search_des,3,65));
			
			$video_type=array();
			$video_type[0]="Video upload on server";
			$video_type[1]="MP3 File";
			$video_type[2]="Embeded code";
			$form->register('video_type',"Video Type",new dropdowncontrol($object->video_type,$video_type));
			
			$form->register('file_id','Select file', new ajax_select_file('file_id',0,$object->file_id,true));
			$form->register('thumbnail','Select Thumbnail', new ajax_select_file('thumbnail',0,$object->thumbnail,false));
			
			$form->register('youtube_embed','Embed Code',new texteditorcontrol($object->youtube_embed,3,65,false));
			$form->register('use_own_thumbnail','Force use uploaded thumbnail', new checkboxcontrol($object->use_own_thumbnail));
			$form->register('prior','This is prior video', new checkboxcontrol($object->prior));
			$form->register('highlighted','Highlighted', new checkboxcontrol($object->highlighted));
			
			$form->register('cat_id','Category',new dropdowncontrol($object->cat_id, $cats));
			
			
			$form->register('submit','',new buttongroupcontrol('Save','','Cancel'));
			return $form;
		}


		/**
		* Video Update
		* 
		* @param mixed $values
		* @param mixed $object
		*/
		function video_update($values,$object) {
			$object->title = $values['title'];
			$object->title2 = $values['title2'];
			$object->seo_name = $values['seo_name'];
			if (trim($object->seo_name) == "")
				$object->seo_name = _to_vietnamese_with_nomark($values['title']);
			else
				$object->seo_name = _to_vietnamese_with_nomark($values['seo_name']);
			
			$object->seo_name=_ab_check_seoname("videomodule_video",$object->seo_name, $object->id);
			$object->search_des = $values['search_des'];
			
			
			$object->video_type = intval($values['video_type']);
			$object->file_id= intval($values['file_id']);
			$object->thumbnail= intval($values['thumbnail']);
			$object->youtube_embed= $values['youtube_embed'];
			$object->use_own_thumbnail= isset($values['use_own_thumbnail'])?1:0;
			$object->highlighted= isset($values['highlighted'])?1:0;
			$object->prior= isset($values['prior'])?1:0;
			$object->cat_id =intval($values['cat_id']);
			
			if (!isset($object->id))
				$object->postdate=aboid_getCurrentTime();
			
			return $object;
		}

	}
?>
